/**
 * 描述: jQuery扩展
 */

(function() {
  "use strict";

  jQuery.fn.extend({
    /**
     * 在当前元素中根据name查找元素
     * @param inputName
     * @returns {jQuery}
     */
    r_byName: function(inputName) {
      if(this.length === 0) {
        return this;
      }

      return this.map(function(index, el) {
        if(this.tagName.toLowerCase() === "form") {
          var __input = this[inputName] ? this[inputName] : undefined;

          if(__input !== undefined) {
            if(rapid.isDefined(__input.length)) {
              return jQuery.makeArray(__input);
            }

            return __input;
          }

          return;
        }

        return jQuery(this).find(":input[name='" + inputName + "']").toArray();
      });
    },

    /**
     * 通用赋值、取值函数
     * @returns {*|jQuery}
     */
    r_val: function() {
      var __len = this.length, __$_s, __s, __i;

      if(arguments.length === 1) {
        if(this.length <= 0) {
          return this;
        }

        var __data = rapid.nvl(arguments[0]);

        for(__i = 0; __i < __len; __i++) {
          __s = this[__i];
          __$_s = jQuery(__s);

          if(rapid.isUndefined(__s.type) || __s.tagName.toLowerCase() === "button") {
            if(rapid.REGEX_TAG_IMG.test(__s.tagName)) {
              /*if(rapid.isEnum(__data)) {
               __data = __data[rapid.propName(__data, "value")];
               }*/
              __$_s.attr("src", __data.toString());

            } else {
              /*if(rapid.isEnum(__data)) {
               __data = __data[rapid.propName(__data, "value")];
               }*/

              __$_s.html(__data.toString());
            }

          } else {
            switch(__s.type) {
              case "radio":
              case "checkbox":
                /*if(rapid.isEnum(__data)) {
                 __data = __data[rapid.VALUE_FIELD];
                 }*/
                rapid.checked(__$_s, __data.toString());
                break;

              case "file":
                rapid._error_("input file控件无法调用r_val方法。");
                break;

              default:
                /* if(rapid.isEnum(__data)) {
                 __data = __data[rapid.VALUE_FIELD];
                 }*/
                __$_s.val(__data.toString());
                break;
            }
          }
        }

        return this;

      } else {
        if(__len <= 0) {
          return "";
        }

        if(__len > 1) {
          rapid._error_("fn.r_val()方法只能用于单个元素。");
        }

        var __value = "";

        for(__i = 0; __i < __len; __i++) {
          __s = this[__i];
          __$_s = jQuery(__s);

          if(rapid.isUndefined(__s.type)) {
            if(rapid.REGEX_TAG_IMG.test(__s.tagName)) {
              __value = __$_s.attr("src");
            } else {
              __value = __$_s.html();
            }
          } else {
            switch(__s.type) {
              case "radio":
              case "checkbox":
                __value = __$_s.filter(":checked").val();
                break;
              case "file":
                rapid._error_("input file控件无法调用r_val方法。");
                break;
              default:
                __value = __$_s.val();
                break;
            }
          }
        }

        return rapid.nvl(__value, "");
      }
    },

    /**
     * 移除或添加样式
     * @param {String} className
     * @param {Boolean} [value]
     * @returns {jQuery}
     */
    r_toggleClass: function(className, value) {
      if(rapid.isDefined(value)) {
        if(rapid.str.hasValue(className)) {
          this[value ? "addClass" : "removeClass"](className);
        }

      } else {
        this.toggleClass(className);
      }

      return this;
    },

    /**
     * 判断元素的宽度是否最大化
     * @returns {Boolean}
     */
    r_isMaxWidth: function() {
      return this.outerWidth(true) === this.parent().r_innerWidth();
    },

    /**
     * 判断元素是否可见
     * @returns {Boolean}
     */
    r_isVisible: function() {
      if(this.length === 0) {
        return false;
      }

      return !this.is(":hidden") && this.r_visible();
    },

    /**
     * 判断元素是否是window或body
     * @returns {*}
     */
    r_isWindowOrBody: function() {
      return this.is("body") || jQuery.isWindow(this[0]);
    },

    /**
     * 判断或设置元素是否可见（r-visible|r-invisible）
     * @returns {Boolean|jQuery}
     */
    r_visible: function() {
      if(arguments.length === 0) {
        if(this.length === 0) {
          return false;
        }
        return this.css("visibility") !== "hidden";
      }

      if(this.length === 0) {
        return this;
      }

      if(arguments[0] === true) {
        this.removeClass("r-invisible").addClass("r-visible");
      } else {
        this.removeClass("r-visible").addClass("r-invisible");
      }

      return this;
    },

    /**
     * 显示元素（r-hide)
     * @returns {jQuery}
     */
    r_show: function() {
      if(this.hasClass("r-hide")) {
        return this.removeClass("r-hide");
      }

      return this;
    },

    /**
     * 隐藏元素（r-hide)
     * @returns {*}
     */
    r_hide: function() {
      if(this.hasClass("r-hide")) {
        return this;
      }
      return this.addClass("r-hide");
    },

    /**
     * 获取或设置元素禁用状态
     * @returns {Boolean|jQuery}
     */
    r_disabled: function() {
      if(arguments.length === 0) {
        return rapid.nvl(this.data(rapid.KEY_DISABLED), false);

      } else {
        this.r_toggleClass("r-state-disabled", arguments[0])
            .data(rapid.KEY_DISABLED, arguments[0]);
        return this;
      }
    },

    /**
     * 获取或设置当前元素在指定容器中的位置
     * @param {*} container
     * @param {String|JSON} [position]
     * @param {Boolean} [emUnit]
     * @returns {*}
     */
    r_offset: function(container, position, emUnit) {
      if(arguments.length <= 1 || position === "absolute" || position === "fixed") {
        if(this.length === 0) {
          return {
            top: 0,
            left: 0
          };
        }

        var __$_container;

        if(rapid.isEmpty(container)) {
          return this.offset();

        } else {
          __$_container = jQuery(container);
          var __$_body = null,
            __is_body = __$_container.is("body"),
            __body_offset;

          if(__is_body || rapid.isWindow(__$_container)) {
            __$_body = __is_body ? __$_container : jQuery("body");

            var __scroll_top = __$_body.scrollTop();

            if(__scroll_top === 0) {
              __scroll_top = $(window).scrollTop();

              if(__scroll_top === 0) {
                return this.offset();
              }
            }

            if(position === "fixed") {
              __body_offset = this.offset();

              return {
                top: __body_offset.top - __scroll_top,
                left: __body_offset.left
              };
            }

            __$_container = __$_body;
          }

          var __c_offset = __$_container.offset();
          __body_offset = this.offset();

          return {
            top: __body_offset.top - __c_offset.top,
            left: __body_offset.left - __c_offset.left
          };
        }
      }

      if(this.length === 0) {
        return this;
      }

      __$_container = jQuery(container);
      __$_container = __$_container.is("body") ? jQuery(window) : __$_container;

      var __position = rapid.offset({
        width: this.outerWidth(true),
        height: this.outerHeight(true)
      }, {
        width: __$_container.innerWidth(),
        height: __$_container.innerHeight()
      }, position);

      var __font_size = rapid.parseFloat(this.css("font-size"));
      if(__position.hasOwnProperty("top")) {
        __position.top = emUnit ? rapid.parseEM(__position.top, __font_size) : __position.top + "px";
      }

      if(__position.hasOwnProperty("right")) {
        __position.right = emUnit ? rapid.parseEM(__position.right, __font_size) : __position.top + "px";
      }

      if(__position.hasOwnProperty("bottom")) {
        __position.bottom = emUnit ? rapid.parseEM(__position.bottom, __font_size) : __position.top + "px";
      }

      if(__position.hasOwnProperty("left")) {
        __position.left = emUnit ? rapid.parseEM(__position.left, __font_size) : __position.top + "px";
      }

      this.css(__position);

      __position = null;
      return this;
    },

    /**
     * 设置元素大小
     * @param {*} container
     * @param {Number} width
     * @param {Number} height
     * @returns {jQuery}
     */
    r_size: function(container, width, height) {
      if(this.length === 0) {
        return this;
      }

      var __$_container;

      if(jQuery.isEmptyObject(container)) {
        __$_container = jQuery(window);
      } else {
        __$_container = jQuery(container);
      }

      if(width <= 0) {
        width = __$_container.outerWidth(false);
      }
      if(height <= 0) {
        height = __$_container.outerHeight(false);
      }

      this.css({
        width: width + "px",
        height: height + "px"
      });

      __$_container = null;

      return this;
    },

    /**
     * 设置焦点
     * @returns {jQuery}
     */
    r_focus: function() {
      if(this.length === 1 && !this.is(":focus")) {
        this.focus();
      }

      return this;
    },

    /**
     * 移除焦点
     * @returns {jQuery}
     */
    r_blur: function() {
      if(this.length === 1 && this.is(":focus")) {
        this.blur();
      }

      return this;
    },

    /**
     *
     * @returns {Number}
     */
    r_width: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).width();
      }

      return this.is(":visible") ? this.width() : 0;
    },

    /**
     *
     * @returns {Number}
     */
    r_height: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).height();
      }

      return this.is(":visible") ? this.height() : 0;
    },

    /**
     *
     * @returns {Number}
     */
    r_innerWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).innerWidth();
      }

      return this.is(":visible") ? this.innerWidth() : 0;
    },

    /**
     *
     * @returns {Number}
     */
    r_innerHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).innerHeight();
      }

      return this.is(":visible") ? this.innerHeight() : 0;
    },

    /**
     *
     * @returns {Number}
     */
    r_outerWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).outerWidth();
      }

      return this.is(":visible") ? this.outerWidth(arguments.length === 2 ? arguments[1] : false) : 0;
    },

    /**
     *
     * @returns {Number}
     */
    r_outerHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || (arguments.length === 1 && arguments[0] !== false && this.is(arguments[0] === true ? "body" : arguments[0]))) {
        return jQuery(window).outerHeight();
      }

      return this.is(":visible") ? this.outerHeight(arguments.length === 2 ? arguments[1] : false) : 0;
    },

    /**
     * 获取元素左右边框宽度之和
     * @returns {Number}
     */
    r_borderWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || this.is("body")) {
        return 0;
      }

      var __value = parseFloat(this.css("border-left-width")) + parseFloat(this.css("border-right-width"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     * 获取元素上下边框宽度之和
     * @returns {Number}
     */
    r_borderHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || this.is("body")) {
        return 0;
      }

      var __value = parseFloat(this.css("border-top-width")) + parseFloat(this.css("border-bottom-width"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     * 获取元素左右外边距之和
     * @returns {Number}
     */
    r_marginWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || this.is("body")) {
        return 0;
      }

      var __value = parseFloat(this.css("margin-left")) + parseFloat(this.css("margin-right"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     * 获取元素上下外边距之和
     * @returns {Number}
     */
    r_marginHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0]) || this.is("body")) {
        return 0;
      }

      var __value = parseFloat(this.css("margin-top")) + parseFloat(this.css("margin-bottom"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     * 获取元素左右内边距之和
     * @returns {Number}
     */
    r_paddingWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0])) {
        return 0;
      }

      var __value = parseFloat(this.css("padding-left")) + parseFloat(this.css("padding-right"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     * 获取元素上下内边距之和
     * @returns {Number}
     */
    r_paddingHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      if(jQuery.isWindow(this[0])) {
        return 0;
      }

      var __value = parseFloat(this.css("padding-top")) + parseFloat(this.css("padding-bottom"));
      if(!rapid.isNumber(__value)) {
        __value = 0;
      }
      return __value;
    },

    /**
     *
     * @returns {Number}
     */
    r_scrollHeight: function() {
      if(this.length === 0) {
        return 0;
      }

      return this[0].scrollHeight;
    },

    /**
     *
     * @returns {Number}
     */
    r_scrollWidth: function() {
      if(this.length === 0) {
        return 0;
      }

      return this[0].scrollWidth;
    },

    /**
     * 从DOM对象的style属性中获取
     * @param styleAttr
     * @returns {*}
     */
    r_css: function(styleAttr) {
      if(this.length === 0) {
        return "";
      }

      if(rapid.str.isEmpty(styleAttr)) {
        return "";
      }

      if(styleAttr.indexOf("-") !== -1) {
        var __temp = styleAttr.split("-"),
          __len = __temp.length;

        styleAttr = __temp[0];

        for(var __i = 1; __i < __len; __i++) {
          styleAttr += __temp[__i].r_pascalCase();
        }
      }

      return rapid.nvl(this[0].style[styleAttr], null);
    },

    r_transform: function(value, is3D) {
      if(arguments.length === 0) {
        if(this.length === 0) {
          return null;
        }

        var __transform = this.css("transform");

        return rapid.nvl(__transform, "", function(v) {
          if(v === "none") {
            return [1, 0, 0, 1, 0, 0];
          }

          var __tmp = v.replace(is3D ? /^matrix3d\(/ : /^matrix\(/, "").replace(")", "").r_trimAll().split(","),
            __i = 0,
            __len = is3D ? 16 : 6,
            __rs = [];

          for(__i; __i < __len; __i++) {
            __rs.push(parseFloat(__tmp[__i]));
          }

          return __rs;
        });
      }

      if(this.length === 0) {
        return this;
      }

      if(value === "" || value === null) {
        value = "";
      }

      this.css({
        "-ms-transform": value,
        "-moz-transform": value,
        "-webkit-transform": value,
        "-o-transform": value,
        "transform": value
      });

      return this;
    },

    r_cssHeight: function(value, emUnit) {
      if(value === 0) {
        return this.height(0);
      }

      if(rapid.isString(value)) {
        return this.css("height", value);
      }

      if(rapid.nvl(this.css("box-sizing")) !== "border-box") {
        value -= this.r_paddingHeight();
      }

      return this.css("height", emUnit === true || emUnit === "em" ? rapid.parseEM(value) : value + "px");
    },

    r_cssWidth: function(value, emUnit) {
      if(value === 0) {
        return this.width(0);
      }

      if(rapid.isString(value)) {
        return this.css("width", value);
      }

      if(rapid.nvl(this.css("box-sizing")) !== "border-box") {
        value -= this.r_paddingWidth();
      }

      return this.css("width", emUnit ? rapid.parseEM(value) : value + "px");
    },

    /**
     *
     * @returns {{width: Number, height: Number}}
     */
    r_textSize: function() {
      if(this.length === 0) {
        return {
          width: 0,
          height: 0
        };
      }

      var __font_size = parseFloat(this.css("font-size").replace("px", "").replace("em", ""));

      return {width: this.text().length * __font_size, height: __font_size};
    },

    /**
     * 将表单元素序列化，被禁用的表单元素不会被序列化
     * @param {Function} serializationCallback 序列化处理函数
     * @returns {jQuery}
     */
    r_serialize: function(serializationCallback) {
      if(rapid.isFunction(serializationCallback)) {
        return serializationCallback.apply(
          this.map(function() {
            var __elements = jQuery.prop(this, "elements");
            return __elements ? jQuery.makeArray(__elements) : this;

          }).filter(function() {
            var __type = this.type;

            return this.name && !jQuery(this).is(":disabled") &&
                   rapid.REGEX_TAG_SUBMITTABLE.test(this.nodeName) && !rapid.REGEX_TAG_SUBMITTER_TYPES.test(__type) &&
                   (this.checked || !rapid.REGEX_TAG_CHECKABLE_TYPES.test(__type));

            //return this.name &&
            //(this.checked || rapid.REGEX_TAG_SELECT_TEXTAREA.test(this.nodeName) ||
            //  rapid.REGEX_TAG_INPUT_TYPES.test(__type));
          })
        );
      }
    },

    /**
     * 将表单中的控件序列化成JSON，被禁用的表单元素不会被序列化
     * @returns {{}}
     */
    r_serializeJson: function() {
      if(this.length === 0) {
        return {};
      }

      var __$_els;

      if(!this.is(":input") && !this.is("form")) {
        __$_els = this.find(":input");
      } else {
        __$_els = this;
      }

      if(__$_els.length === 0) {
        return {};
      }

      var __json = {};

      __$_els.r_serialize(function() {
        var __i = 0,
          __len = this.length,
          __ui, __el, __value, __name;

        for(__i; __i < __len; __i++) {
          __el = this[__i];
          __name = __el.name;
          __value = jQuery(__el).val();

          __value = __value === "on" ? "" : __value;

          if(rapid.isUndefined(__json[__name])) {
            __json[__name] = __value;

          } else {
            if(!rapid.isArray(__json[__name])) {
              __json[__name] = [__json[__name], __value];

            } else {
              if(rapid.isArray(__value)) {
                __json[__name] = __json[__name].concat(__value);

              } else {
                __json[__name].push(__value);
              }
            }
          }
        }
      });

      return __json;
    },

    /**
     * 将表单中的控件序列化成JSON数组，被禁用的表单元素不会被序列化
     * @returns {Array.<{}>}
     */
    r_serializeJsonArray: function() {
      if(this.length === 0) {
        return [];
      }

      var __arr = [];

      this.each(function() {
        __arr.push(jQuery(this).r_serializeJson());
      });

      return __arr;
    },

    /**
     * 将表单中的控件序列化成JSON字符串，被禁用的表单元素不会被序列化
     * @returns {String}
     */
    r_serializeJsonString: function() {
      return rapid.parseString(this.r_serializeJson());
    },

    /**
     * 将表单中的控件序列化成JSON数组字符串，被禁用的表单元素不会被序列化
     * @returns {String}
     */
    r_serializeJsonArrayString: function() {
      return rapid.parseString(this.r_serializeJsonArray());
    },

    /**
     *
     * @returns {Number}
     */
    r_stopPointerEvents: function() {
      if(this.length === 0) {
        return this;
      }

      var __$_s = this.css("pointer-events", "none");
      return setTimeout(function() {
        __$_s.css("pointer-events", "auto");
      }, arguments.length === 1 ? arguments[0] : 350);
    },

    r_userUnSelect: function(value) {
      if(this.length === 0) {
        return this;
      }

      this.r_toggleClass("r-user-unselect", value);
      return this;
    },

    r_scrollTo: function(targetSelector, options) {
      var __$_el = jQuery(this),
        __$_child;

      //a.scrollIntoView

      options = rapid.extend(true, {
        align: "end",
        dir: "all",
        offset: {top: 0, left: 0},
        animate: 150
      }, options);

      if(options.dir === null) {
        return this;
      }

      if(rapid.isString(targetSelector)) {
        __$_child = __$_el.find(targetSelector);

      } else {
        __$_child = jQuery(targetSelector);
      }

      __$_child = __$_child.eq(0);

      if(__$_child.length === 0) {
        return this;
      }

      var __pos = __$_child.offset(),
        __top = __pos.top,
        __left = __pos.left,
        __animate = !(rapid.isWindow(__$_el) || __$_el.is(document) || options.animate === false || options.animate === 0),
        __el_offset = null, __chd_offset = null,
        __scroll_left_offset = null, __scroll_top_offset = null,
        __cld_top, __el_top, __cld_left, __el_left;

      if((options.dir === "all" || options.dir === "x") && __left !== 0) {
        if(__left > 0) {
          __chd_offset = __chd_offset !== null ? __chd_offset : __$_child.offset();
          __el_offset = __el_offset !== null ? __el_offset : __$_el.offset();
          __cld_left = __chd_offset.left;
          __el_left = __el_offset.left;
          __scroll_left_offset = __cld_left + __$_child.outerWidth(true) - (__$_el.innerWidth() + __el_left);

          if(__scroll_left_offset > 0) {
            if(options.align === "start") {
              __scroll_left_offset = __cld_left - __el_left + __$_el.scrollLeft() + options.offset.left;
            } else {
              __scroll_left_offset = __scroll_left_offset + __$_el.scrollLeft() + options.offset.left;
            }
          } else {
            __scroll_left_offset = null;
          }

        } else if(__left < 0) {
          __chd_offset = __chd_offset !== null ? __chd_offset : __$_child.offset();
          __el_offset = __el_offset !== null ? __el_offset : __$_el.offset();
          __cld_left = __chd_offset.left;
          __el_left = __el_offset.left;
          __scroll_left_offset = __cld_left - __el_left + __$_el.scrollLeft() + options.offset.left;
        }
      }

      if((options.dir === "all" || options.dir === "y") && __top !== 0) {
        if(__top > 0) {
          __chd_offset = __chd_offset !== null ? __chd_offset : __$_child.offset();
          __el_offset = __el_offset !== null ? __el_offset : __$_el.offset();
          __cld_top = __chd_offset.top;
          __el_top = __el_offset.top;
          __scroll_top_offset = __cld_top + __$_child.outerHeight(true) - (__$_el.innerHeight() + __el_top);

          if(__scroll_top_offset > 0) {
            if(options.align === "start") {
              __scroll_top_offset = __cld_top - __el_top + __$_el.scrollTop() + options.offset.top;
            } else {
              __scroll_top_offset = __scroll_top_offset + __$_el.scrollTop() + options.offset.top;
            }
          } else {
            __scroll_top_offset = null;
          }

        } else if(__top < 0) {
          __chd_offset = __chd_offset !== null ? __chd_offset : __$_child.offset();
          __el_offset = __el_offset !== null ? __el_offset : __$_el.offset();
          __cld_top = __chd_offset.top;
          __el_top = __el_offset.top;
          __scroll_top_offset = __cld_top - __el_top + __$_el.scrollTop() + options.offset.top;
        }
      }

      if(__scroll_left_offset !== null && __scroll_top_offset !== null) {
        if(!__animate) {
          __$_el[0].scrollTo(__scroll_left_offset, __scroll_top_offset);

        } else {
          __$_el.animate({
            scrollTop: __scroll_top_offset,
            scrollLeft: __scroll_left_offset
          }, options.animate);
        }

      } else {
        if(__scroll_top_offset !== null) {
          if(!__animate) {
            __$_el.scrollTop(__scroll_top_offset);
          } else {
            __$_el.animate({scrollTop: __scroll_top_offset}, options.animate);
          }
        }

        if(__scroll_left_offset !== null) {
          if(!__animate) {
            __$_el.scrollLeft(__scroll_left_offset);
          } else {
            __$_el.animate({scrollLeft: __scroll_left_offset}, options.animate);
          }
        }
      }

      return this;
    },

    r_scrollIntoView: function(offset) {

    },

    r_toggleOverflowScrolling: function(value) {
      if(value) {
        this.removeClass("r-prevent-overflow-scrolling");
      } else {
        this.addClass("r-prevent-overflow-scrolling");
      }

      return this;
    },

    r_on: function(types, selector, data, fn, one) {
      var __selector, __data, __fn;

      if(rapid.isFunction(selector)) {
        __fn = selector;
        __selector = null;

      } else if(rapid.isFunction(data)) {
        __fn = data;
        if(rapid.isString(selector)) {
          __selector = selector;
        } else {
          __data = selector;
        }

      } else if(rapid.isFunction(fn)) {
        __fn = fn;
        __selector = selector;
        __data = data;

      } else {
        rapid._error_("jQuery对象的r_on方法参数不正确：没有定义有效的函数。");
      }

      if(/^(v|h)swipe/.test(types)) {
        var __x = false,
          __y = false;

        if(types.r_startWith("v")) {
          __y = true;
        }

        if(types.r_startWith("h")) {
          __x = true;
        }

        // var __en = rapid.func._getNameAndSpace_(types);

        rapid.SwipeEvent(this, {
          namespace: __ns,
          child: __selector,
          x: __x,
          y: __y
        }).on("end", __data, __fn);

        return this;
      }

      var __types = rapid.event.compatible(types);

      if(__types !== null) {
        this.on(__types, __selector, __data, function(e) {
          if(jQuery(this).data(rapid.KEY_DISABLED) === true) {
            rapid.preventDefault(e);
            e.stopImmediatePropagation();
            e.stopPropagation();
            return false;

          } else {
            if(rapid.isFunction(__fn)) {
              return __fn.apply(this, arguments);
            }
          }
        }, one);
      }

      return this.on(types, __selector, __data, function(e) {
        if(jQuery(this).data(rapid.KEY_DISABLED) === true) {
          rapid.preventDefault(e);
          e.stopImmediatePropagation();
          e.stopPropagation();
          return false;

        } else {
          if(rapid.isFunction(__fn)) {
            return __fn.apply(this, arguments);
          }
        }
      }, one);
    },

    r_off: function(types, selector, fn) {
      var __types = rapid.event.compatible(types);

      if(__types !== null) {
        this.removeData(rapid.KEY_DISABLED).off(__types, selector, fn);
      }

      return this.removeData(rapid.KEY_DISABLED).off(types, selector, fn);
    }
  });
})();